// pages/pay/index.js
const App = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inputValue:0,
    points:0,
    isLogin: false,
    disabled: false, //按钮禁用
    shopid:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var scene = decodeURIComponent(options.scene)
    console.log(scene)
    this.setData({
      shopid:scene
    })
  },
  onShow() {
    let _this = this;
    _this.setData({
      isLogin: App.checkIsLogin()
    });
  },
  denglu:function(){
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  bindKeyInput: function (e) {
    let _this = this

    App._get('Pay/integralJiSuan', {money:e.detail.value}, function(result) {
      _this.setData({
        points:result.data.integral,
        inputValue:e.detail.value
      });
    });
  },
  
  /**
   * 立即充值
   */
  onSubmit(e) {
    let _this = this;

    // 按钮禁用
    _this.setData({
      disabled: true
    });
    // 提交到后端
    App._post_form('pay/submit', {
      customMoney: _this.data.inputValue,
      shopid:_this.data.shopid
    }, (result) => {

      // 发起微信支付
      App.wxPayment({
        payment: result.data.payment,
        success() {
          App.showSuccess(result.msg.success, () => {
            // wx.navigateBack();
            wx.redirectTo({
              url: '/pages/pay/order/index?id='+result.data.order.order_id
            });
          });
        },
        fail(res) {
          App.showError(result.msg.error);
        },
        complete(res) {

        }
      });

    }, false, () => {
      // 解除禁用
      _this.setData({
        disabled: false
      });
    });
  },
})